package objectdiagrameditor.diagram;

import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;

import objectdiagrameditor.features.link.AddLinkConnectionFeature;
import objectdiagrameditor.features.link.CreateLinkConnectionFeature;
import objectdiagrameditor.features.object.AddObjectFeature;
import objectdiagrameditor.features.object.CreateObjectFeature;
import objectdiagrameditor.features.object.LayoutObjectFeature;


public class ObjectDiagramEditorFeatureProvider extends DefaultFeatureProvider {

	public ObjectDiagramEditorFeatureProvider(IDiagramTypeProvider dtp) {
		super(dtp);
	}

	@Override
	public ICreateFeature[] getCreateFeatures() {
		return new ICreateFeature[] {new CreateObjectFeature(this)};
	}
	
	@Override
	public ICreateConnectionFeature[] getCreateConnectionFeatures() {
		return new ICreateConnectionFeature[] {new CreateLinkConnectionFeature(this)};
	}
	
	@Override
	public IAddFeature getAddFeature(IAddContext context) {
		if (context instanceof IAddConnectionContext  && context.getNewObject() instanceof fUML.Semantics.Classes.Kernel.Link) {
			return new AddLinkConnectionFeature(this);
		} else if (context instanceof IAddContext  && context.getNewObject() instanceof  fUML.Semantics.Classes.Kernel.Object) {
			return new AddObjectFeature(this);
		}

		return super.getAddFeature(context);
	}
	
	@Override
	public ILayoutFeature getLayoutFeature(ILayoutContext context) {
		// TODO: check for right domain object instances below
		if (context.getPictogramElement() instanceof ContainerShape /* && getBusinessObjectForPictogramElement(context.getPictogramElement()) instanceof <DomainObject> */) {
			return  new LayoutObjectFeature(this);
		}
	
		return super.getLayoutFeature(context);
	}
}
